package com.turing.post.transaction.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.turing.post.util.PCPSUtil;

/**
 * 商户交易流水
 * 
 * @author zxl
 * @date 2012-12-17
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "MCHTRADDETAIL")
@IdClass(MchTradDetail.class)
public class MchTradDetail implements Serializable {
	/**
	 * 商户ID
	 */
	private String merchantNo;
	/**
	 * 帐务日期
	 */
	private Date tranDate;
	/**
	 * 流水号
	 */
	private String tranSeqNo;
	/**
	 * 冲正/被流水号
	 */
	private String cancelTranSeqNo;
	/**
	 * 交易码
	 */
	private String tranCode;
	/**
	 * 交易时间
	 */
	private Date tranTime;
	/**
	 * 商户请求流水
	 */
	private String mrchSeqNo;
	/**
	 * 卡号
	 */
	private String cardNo;
	/**
	 * 交易金额
	 */
	private BigInteger amount;
	/**
	 * 手续费
	 */
	private BigInteger fee;
	/**
	 * 积分支付额
	 */
	private BigInteger scorePaidAmount;
	/**
	 * 实际积分支付额
	 */
	private BigInteger factScorePaidAmount;
	/**
	 * 帐户子系统应答流水号
	 */
	private String accAckSeqNo;
	/**
	 * 商户业务摘要
	 */
	private String mrchAbstract;
	/**
	 * 会员ID
	 */
	private BigInteger membershipId;
	/**
	 * 会员卡卡号
	 */
	private String vipCardNo;
	/**
	 * 积分产生流水号
	 */
	private String scoreTranSeqNo;
	/**
	 * 积分支付流水号
	 */
	private String scorePaidTranSeqNo;
	/**
	 * 本次积分发生
	 */
	private BigInteger scoreAmount;
	/**
	 * 渠道积分余额
	 */
	private BigInteger score;
	/**
	 * 积分补登时间
	 */
	private Date reScoreTime;
	/**
	 * 积分补登操作员
	 */
	private String reScoreOperNo;
	/**
	 * 积分补登备注
	 */
	private String reScoreRemark;
	/**
	 * 退货/被退货交易日期
	 */
	private Date otherTranDate;
	/**
	 * 退货/被退货交易流水
	 */
	private String otherTranSeqNo;
	/**
	 * 退货/被退货商户流水号
	 */
	private String otherMrchSeqNo;
	/**
	 * 终端号
	 */
	private String terminalNo;
	/**
	 * 终端批次号
	 */
	private String termSettBatchNo;
	/**
	 * 终端流水号
	 */
	private String termSeqNo;
	/**
	 * 商户操作员
	 */
	private String mrchTellerNo;
	/**
	 * 商户分支机构
	 */
	private String mrchBrchNo;

	/**
	 * 调帐/错帐日期
	 */
	private Date adjustTranDate;
	
	/**
	 * 调帐/被调流水号
	 */
	private String adjustTranSeqNo;
	
	/**
	 * 调帐人ID
	 */
	private BigInteger adjustOperId;
	
	/**
	 * 调帐备注
	 */
	private String adjustReamrk;
	
	public MchTradDetail() {
		super();
	}

	@Id
	@Column(name = "MERCHANTNO", nullable = false)
	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	@Id
	@Column(name = "TRANDATE", nullable = false)
	public Date getTranDate() {
		return tranDate;
	}

	public void setTranDate(Date tranDate) {
		this.tranDate = tranDate;
	}

	@Id
	@Column(name = "TRANSEQNO", nullable = false)
	public String getTranSeqNo() {
		return tranSeqNo;
	}

	public void setTranSeqNo(String tranSeqNo) {
		this.tranSeqNo = tranSeqNo;
	}

	@Column(name = "CANCELTRANSEQNO")
	public String getCancelTranSeqNo() {
		return cancelTranSeqNo;
	}

	public void setCancelTranSeqNo(String cancelTranSeqNo) {
		this.cancelTranSeqNo = cancelTranSeqNo;
	}

	/**
	 * 支付交易
	 */
	public static final String TRANCODE_PAID = "9010";
	/**
	 * 支付冲正交易
	 */
	public static final String TRANCODE_PAID_CORR = "9011";
	/**
	 * 支付撤销交易
	 */
	public static final String TRANCODE_PAID_CANCEL = "9020";
	/**
	 * 支付撤销冲正交易
	 */
	public static final String TRANCODE_PAID_CANCEL_CORR = "9021";
	/**
	 * 退货交易
	 */
	public static final String TRANCODE_PAID_REJECT = "9030";
	/**
	 * 卡充值
	 */
	public static final String TRANCODE_DEPOSIT = "9040";
	/**
	 * 卡充值冲正
	 */
	public static final String TRANCODE_DEPOSIT_CORR = "9041";
	/**
	 * 卡充值撤销
	 */
	public static final String TRANCODE_DEPOSIT_CANCEL = "9050";
	/**
	 * 卡充值撤销冲正
	 */
	public static final String TRANCODE_DEPOSIT_CANCEL_CORR = "9051";

	@Column(name = "TRANCODE", nullable = false)
	public String getTranCode() {
		return tranCode;
	}

	public void setTranCode(String tranCode) {
		this.tranCode = tranCode;
	}

	@Column(name = "TRANTIME", nullable = false)
	public Date getTranTime() {
		return tranTime;
	}

	public void setTranTime(Date tranTime) {
		this.tranTime = tranTime;
	}

	@Column(name = "MRCHSEQNO")
	public String getMrchSeqNo() {
		return mrchSeqNo;
	}

	public void setMrchSeqNo(String mrchSeqNo) {
		this.mrchSeqNo = mrchSeqNo;
	}

	@Column(name = "CARDNO")
	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	@Column(name = "AMOUNT")
	public BigInteger getAmount() {
		return amount;
	}

	public void setAmount(BigInteger amount) {
		this.amount = amount;
	}

	@Column(name = "FEE")
	public BigInteger getFee() {
		return fee;
	}

	public void setFee(BigInteger fee) {
		this.fee = fee;
	}

	@Column(name = "SCOREPAIDAMOUNT")
	public BigInteger getScorePaidAmount() {
		return scorePaidAmount;
	}

	public void setScorePaidAmount(BigInteger scorePaidAmount) {
		this.scorePaidAmount = scorePaidAmount;
	}

	@Column(name = "FACTSCOREPAIDAMOUNT")
	public BigInteger getFactScorePaidAmount() {
		return factScorePaidAmount;
	}

	public void setFactScorePaidAmount(BigInteger factScorePaidAmount) {
		this.factScorePaidAmount = factScorePaidAmount;
	}

	@Column(name = "ACCACKSEQNO")
	public String getAccAckSeqNo() {
		return accAckSeqNo;
	}

	public void setAccAckSeqNo(String accAckSeqNo) {
		this.accAckSeqNo = accAckSeqNo;
	}

	@Column(name = "MRCHABSTRACT")
	public String getMrchAbstract() {
		return mrchAbstract;
	}

	public void setMrchAbstract(String mrchAbstract) {
		this.mrchAbstract = mrchAbstract;
	}

	@Column(name = "MEMBERSHIPID")
	public BigInteger getMembershipId() {
		return membershipId;
	}

	public void setMembershipId(BigInteger membershipId) {
		this.membershipId = membershipId;
	}

	@Column(name = "VIPCARDNO")
	public String getVipCardNo() {
		return vipCardNo;
	}

	public void setVipCardNo(String vipCardNo) {
		this.vipCardNo = vipCardNo;
	}

	@Column(name = "SCORETRANSEQNO")
	public String getScoreTranSeqNo() {
		return scoreTranSeqNo;
	}

	public void setScoreTranSeqNo(String scoreTranSeqNo) {
		this.scoreTranSeqNo = scoreTranSeqNo;
	}

	@Column(name = "SCOREPAIDTRANSEQNO")
	public String getScorePaidTranSeqNo() {
		return scorePaidTranSeqNo;
	}

	public void setScorePaidTranSeqNo(String scorePaidTranSeqNo) {
		this.scorePaidTranSeqNo = scorePaidTranSeqNo;
	}

	@Column(name = "SCOREAMOUNT")
	public BigInteger getScoreAmount() {
		return scoreAmount;
	}

	public void setScoreAmount(BigInteger scoreAmount) {
		this.scoreAmount = scoreAmount;
	}

	@Column(name = "SCORE")
	public BigInteger getScore() {
		return score;
	}

	public void setScore(BigInteger score) {
		this.score = score;
	}

	@Column(name = "RESCORETIME")
	public Date getReScoreTime() {
		return reScoreTime;
	}

	public void setReScoreTime(Date reScoreTime) {
		this.reScoreTime = reScoreTime;
	}

	@Column(name = "RESCOREOPERNO")
	public String getReScoreOperNo() {
		return reScoreOperNo;
	}

	public void setReScoreOperNo(String reScoreOperNo) {
		this.reScoreOperNo = reScoreOperNo;
	}

	@Column(name = "RESCOREREMARK")
	public String getReScoreRemark() {
		return reScoreRemark;
	}

	public void setReScoreRemark(String reScoreRemark) {
		this.reScoreRemark = reScoreRemark;
	}

	@Column(name = "OTHERTRANDATE")
	public Date getOtherTranDate() {
		return otherTranDate;
	}

	public void setOtherTranDate(Date otherTranDate) {
		this.otherTranDate = otherTranDate;
	}

	@Column(name = "OTHERTRANSEQNO")
	public String getOtherTranSeqNo() {
		return otherTranSeqNo;
	}

	public void setOtherTranSeqNo(String otherTranSeqNo) {
		this.otherTranSeqNo = otherTranSeqNo;
	}

	@Column(name = "OTHERMRCHSEQNO")
	public String getOtherMrchSeqNo() {
		return otherMrchSeqNo;
	}

	public void setOtherMrchSeqNo(String otherMrchSeqNo) {
		this.otherMrchSeqNo = otherMrchSeqNo;
	}

	@Column(name = "TERMINALNO")
	public String getTerminalNo() {
		return terminalNo;
	}

	public void setTerminalNo(String terminalNo) {
		this.terminalNo = terminalNo;
	}

	@Column(name = "TERMSETTBATCHNO")
	public String getTermSettBatchNo() {
		return termSettBatchNo;
	}

	public void setTermSettBatchNo(String termSettBatchNo) {
		this.termSettBatchNo = termSettBatchNo;
	}

	@Column(name = "TERMSEQNO")
	public String getTermSeqNo() {
		return termSeqNo;
	}

	public void setTermSeqNo(String termSeqNo) {
		this.termSeqNo = termSeqNo;
	}

	@Column(name = "MRCHTELLERNO")
	public String getMrchTellerNo() {
		return mrchTellerNo;
	}

	public void setMrchTellerNo(String mrchTellerNo) {
		this.mrchTellerNo = mrchTellerNo;
	}

	@Column(name = "MRCHBRCHNO")
	public String getMrchBrchNo() {
		return mrchBrchNo;
	}

	public void setMrchBrchNo(String mrchBrchNo) {
		this.mrchBrchNo = mrchBrchNo;
	}

	@Column(name = "ADJUSTTRANDATE")
	public Date getAdjustTranDate() {
		return adjustTranDate;
	}

	public void setAdjustTranDate(Date adjustTranDate) {
		this.adjustTranDate = adjustTranDate;
	}

	@Column(name = "ADJUSTTRANSEQNO")
	public String getAdjustTranSeqNo() {
		return adjustTranSeqNo;
	}

	public void setAdjustTranSeqNo(String adjustTranSeqNo) {
		this.adjustTranSeqNo = adjustTranSeqNo;
	}

	@Column(name = "ADJUSTOPERID")
	public BigInteger getAdjustOperId() {
		return adjustOperId;
	}

	public void setAdjustOperId(BigInteger adjustOperId) {
		this.adjustOperId = adjustOperId;
	}

	@Column(name = "ADJUSTREMARK")
	public String getAdjustReamrk() {
		return adjustReamrk;
	}

	public void setAdjustReamrk(String adjustReamrk) {
		this.adjustReamrk = adjustReamrk;
	}

	public BigInteger getValidateAmount() {
		// 消费
		if (PCPSUtil.compareObject(this.getTranCode(), TRANCODE_PAID))
			return this.getAmount();

		// 充值撤销
		if (PCPSUtil.compareObject(this.getTranCode(), TRANCODE_DEPOSIT_CANCEL))
			return this.getAmount().abs();

		// 消费撤销
		if (PCPSUtil.compareObject(this.getTranCode(), TRANCODE_PAID_CANCEL))
			return this.getAmount().abs();

		// 退货
		if (PCPSUtil.compareObject(this.getTranCode(), TRANCODE_PAID_REJECT))
			return this.getAmount().abs();

		// 充值
		if (PCPSUtil.compareObject(this.getTranCode(), TRANCODE_DEPOSIT))
			return this.getAmount();

		return BigInteger.ZERO;
	}

	@Override
	public int hashCode() {
		return PCPSUtil.getObjectListHashCode(new Object[] { getMerchantNo(),
				getTranDate(), getTranSeqNo() });
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof MchTradDetail))
			return false;
		MchTradDetail other = (MchTradDetail) obj;
		if (!PCPSUtil
				.compareObject(this.getMerchantNo(), other.getMerchantNo()))
			return false;
		if (!PCPSUtil.compareObject(this.getTranDate(), other.getTranDate()))
			return false;
		return PCPSUtil
				.compareObject(this.getTranSeqNo(), other.getTranSeqNo());
	}
}
